﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ToolCalendar
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
            MyIcon.Icon = global::ToolCalendar.Properties.Resources.main;
            SetDefaultLocation();
        }

        #region 托盘图标

        private void MyIcon_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.TopMost = true;
                this.Show();
                WindowState = FormWindowState.Normal;
                this.Focus();
                this.TopMost = false;
            }
        }

        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                this.WindowState = FormWindowState.Minimized;
                this.Hide();
            }
        }

        private void 显示主面板ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Show();
            WindowState = FormWindowState.Normal;
            this.Focus();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.Application.Exit();
        }
        private void 所在目录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var path = System.AppDomain.CurrentDomain.BaseDirectory;
            System.Diagnostics.Process.Start(path);
        }
        private void 开机启动ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RegistryKey R_local = Registry.CurrentUser;
            RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
            R_run.SetValue("Tools", "\"" + Application.ExecutablePath + "\"");
            R_run.Close();
            R_local.Close();
        }

        private void 微软日历ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var obj = new ToolCalendar.MCalendar();
            obj.Show();
        }

        private void 雅虎取色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\Soft\\雅虎屏幕取色.exe");
        }

        private void 帮助wikiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://wiki.517cdn.com/index.php/日历工具集合");
        }
        #endregion

        #region 设置默认位置

        /// <summary>
        /// 默认位置
        /// </summary>
        public void SetDefaultLocation()
        {
            Rectangle rect = new Rectangle();
            rect = Screen.GetWorkingArea(this);

            this.Left = (rect.Width - this.Width) / 2;
            this.Top = (rect.Height - this.Height) / 2;
        }
        #endregion
    }
}
